package com.itany.book.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itany.Common.Common;
import com.itany.mapper.BookListMapper;
import com.itany.pojo.Book;
import com.itany.service.BookListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Author：侍家宇
 * Date：2019-09-18 下午2:11
 * Description：<描述>
 */
@Service
@Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRED)
public class BookListServiceImpl implements BookListService {
    @Autowired
    BookListMapper bookListMapper;

    @Transactional(readOnly = true)
    public PageInfo<Book> findBookAll(Integer page, Integer rows) {
        PageHelper.startPage(page, rows);
        List<Book> list = bookListMapper.findBookAll();
        PageInfo<Book> info = new PageInfo<Book>(list);
        return info;
    }

    /**
     * 启用
     *
     * @param id
     */
    public void modifyEnable(Integer id) {
        Book book = new Book();
        book.setId(id);
        book.setFlag(Common.BookCommons.Book_ENABLE);
        bookListMapper.modifyEnable(book);
    }

    public void modifyDisable(Integer id) {
        Book book = new Book();
        book.setId(id);
        book.setFlag(Common.BookCommons.Book_DISABLE);
        bookListMapper.modifyDisable(book);
    }

    /**
     * 书籍修改前查询
     * @param id
     * @return
     */
    public Book findBook(Integer id) {
        Book book=bookListMapper.findBook(id);
        return book;
    }

    /**
     * 书籍修改
     * @param id
     * @return
     */
    public void modifyBook(Book book) {
        bookListMapper.modifyBook(book);


    }
}